package com.libra.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.libra.model.mq.Teacher;
import com.libra.rabbitmq.hello.serviceImp.SendManyServiceImpl;
import com.libra.rabbitmq.hello.serviceImp.SendServiceImpl;
import com.libra.rabbitmq.publishSubscribe.serviceImp.SendPublishSubscribeServiceImpl;

import java.util.List;
/**
 * 
 * ClassName: mq测试入口 <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON(可选). <br/>
 * date: 2018年8月18日 下午6:30:21 <br/>
 * 生产者:往队列插入数据
 * 消费者:往队列取数据
 * 规则:先进先出
 *
 * @author wangzhch
 * @version 
 * @since JDK 1.8
 */
@RestController
@RequestMapping("mq")
public class RabbitMqController {
	Logger log = LoggerFactory.getLogger(RabbitMqController.class);
	/**hello world*/
    @Autowired
    private SendServiceImpl sendServiceImpl;

    /**竞争模式*/
    @Autowired
    private SendManyServiceImpl sendManyServiceImpl;
    
    @Autowired
    private SendPublishSubscribeServiceImpl sendPublishSubscribeServiceImpl;
    /**
     * 
     * send:(一个生产者,一个消费者). <br/>
     *
     * @author wangzhch
     * @param message
     * @return
     * @since JDK 1.8
     */
    @RequestMapping(value = "/oneToOne" , method = RequestMethod.POST)
    public void oneToOne(@RequestBody Teacher teacher){
    	log.info("sendMsg:{}",JSON.toJSONString(teacher));
        sendServiceImpl.oneToOne(teacher);
    }
    /**
     * 
     * oneToMany:(一个生产者,多个消费者). <br/>
     *
     * @author wangzhch
     * @param list
     * @since JDK 1.8
     */
    @RequestMapping(value = "/oneToMany" , method = RequestMethod.POST)
    public void oneToMany(@RequestBody List<Teacher> list) {
    	if(list == null || list.isEmpty()) {
    		log.info("一对多请求接口集合为空");
    	}
		for (Teacher teacher : list) {
			sendServiceImpl.oneToMany(teacher);
		}
    }
    /**
     * 
     * manyToMany:(多个生产者,多个消费者). <br/>
     *
     * @author wangzhch
     * @param list
     * @since JDK 1.8
     */
    @RequestMapping(value = "/manyToMany" , method = RequestMethod.POST)
    public void manyToMany(@RequestBody List<Teacher> list) {
    	if(list == null || list.isEmpty()) {
    		log.info("多对多请求接口集合为空");
    	}
    	for(Teacher teacher : list) {
    		sendServiceImpl.manyToMany(teacher);
    		sendManyServiceImpl.manyToMany(teacher);
    	}
    }
    /**
     * 
     * publishSubscribe:(发布订阅模式). <br/>
     *
     * @author wangzhch
     * @param teacher
     * @since JDK 1.8
     */
    @RequestMapping(value = "/publishSubscribe", method = RequestMethod.POST)
    public void publishSubscribe(@RequestBody Teacher teacher) {
    	sendPublishSubscribeServiceImpl.publishSubscribe(teacher);
    }
    public static void main(String[] args) {
		String num = null;
		System.out.println(num.equals("0"));
		System.out.println(num.equals("1"));
		System.out.println(num.equals("2"));
		System.out.println(num.equals("3"));
	}
}
